import 'package:flutter/material.dart';

class RadioPage extends StatefulWidget {
  RadioPage({Key? key}) : super(key: key);

  @override
  _RadioPageState createState() => _RadioPageState();
}

class _RadioPageState extends State<RadioPage> {
  var sex = 1;
  var flag = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Radio"),
      ),
      body: Padding(
        padding: EdgeInsets.all(20),
        child: Column(
          children: [
            Row(
              children: [
                Text("男"),
                Radio(
                  value: 1,
                  groupValue: this.sex,
                  onChanged: (v) {
                    setState(() {
                      this.sex = v as int;
                    });
                  },
                ),
                Radio(
                  value: 2,
                  groupValue: this.sex,
                  onChanged: (v) {
                    setState(() {
                      this.sex = v as int;
                    });
                  },
                ),
              ],
            ),
            SizedBox(
              height: 20,
            ),
            RadioListTile(
              value: 1,
              groupValue: this.sex,
              title: Text("这是标题"),
              subtitle: Text("这是二级标题"),
              onChanged: (v) {
                setState(() {
                  this.sex = v as int;
                });
              },
            ),
            RadioListTile(
              value: 2,
              groupValue: this.sex,
              title: Text("这是标题"),
              subtitle: Text("这是二级标题"),
              onChanged: (v) {
                setState(() {
                  this.sex = v as int;
                });
              },
            ),
            SizedBox(
              height: 40,
            ),
            Switch(
                value: this.flag,
                onChanged: (v) {
                  setState(() {
                    this.flag = v;
                  });
                })
          ],
        ),
      ),
    );
  }
}
